--欲掩其耀
local yuyanqiyao = fk.CreateSkill {
    name = "mcdh_yuyanqiyao"
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

Fk:addPoxiMethod {
    name = "#mcdh_yuyanqiyao-poxi",
    card_filter = Util.TrueFunc,
    feasible = function(selected)
        return #selected == 3
    end,
    prompt = function()
        return "#mcdh_yuyanqiyao-choice"
    end
}

yuyanqiyao:addEffect('active',{
    anim_type = "control",
    prompt = "#mcdh_yuyanqiyao-active",
    can_use = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
    card_num = 0,
    card_filter = Util.FalseFunc,
    target_num = 1,
    target_filter = function(self, player,to_select, selected)
        return #selected == 0 and to_select:getHandcardNum() >= 3
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        local target = effect.tos[1]
        local hs = target.player_cards[Player.Hand]
        local suits = {}
        local cids = room:askForPoxi(
                player,
                "#mcdh_yuyanqiyao-poxi",
                { { target.general, hs } },
                nil,
                false
        )
        player:showCards(cids)
        for _, cid in ipairs(cids) do
            local card = Fk:getCardById(cid)
            if not table.find(suits, function(i) return i == card.suit end) then
                table.insert(suits, card.suit)
            end
        end
        if #suits == 1 then
            room:damage({
                from = player,
                to = target,
                damage = 1,
                damageType = fk.FireDamage,
                skillName = self.name
            })
        elseif #suits == 3 then
            local players = 
                    table.filter(
                            room:getOtherPlayers(target),
                            function(p)
                                return p.chained
                            end
                    )
            while #cids > 0 and #players > 0 do
                local _,result = room:askToUseActiveSkill(player,{skill_name = "mcdh_yuyanqiyao_active",prompt = "#mcdh_yuyanqiyao-give",cancelable=false,extra_data={targets=players,cards = cids}})
                if result then
                    for _, cid in ipairs(result.cards) do
                        table.removeOne(cids, cid)
                    end
                    for _, t in ipairs(result.targets) do
                        table.removeOne(players, t)
                    end
                    room:moveCardTo(
                            result.cards,
                            Card.PlayerHand,
                           result.targets[1],
                            fk.ReasonGive,
                            self.name,
                            nil,
                            true,
                            player,
                            nil
                    )
                    if #cids == 0 then break end
                    if player.dead then
                        room:moveCards({
                            ids = cids,
                            toArea = Card.DiscardPile,
                            moveReason = fk.ReasonJustMove,
                            skillName = self.name,
                        })
                        break
                    end
                else
                    break
                end
            end
            if #cids > 0 then
                room:throwCard(cids, self.name, target, player)
            end
            room:drawCards(target, 2, self.name)
        end
    end,
})

Fk:loadTranslationTable {
    ["mcdh_yuyanqiyao"] = "抑辉",
    [":mcdh_yuyanqiyao"] = "『欲掩其耀』<br>出牌阶段限一次，你可以观看一名角色的手牌并展示其中三张牌。若这三张牌花色均相同，你对其造成1点火焰伤害；均不同，你将这些牌交给已横置的角色各一张（未交出的牌弃置），然后其摸两张牌。",
    ["#mcdh_yuyanqiyao-poxi"] = "欲掩其耀",
    ["mcdh_yuyanqiyao_active"] = "欲掩其耀",
    ["#mcdh_yuyanqiyao-active"] = "欲掩其耀:选择一名至少有三张牌的角色",
    ["#mcdh_yuyanqiyao-choice"] = "欲掩其耀:选择以下三张牌展示",
    ["#mcdh_yuyanqiyao-give"] = "欲掩其耀:将其中一张牌交给一名横置的角色",
}

return yuyanqiyao